package both.map.mapView;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import both.map.TerrainType;

public class MapViewCell {

	private TerrainType tileType;

	public MapViewCell() {
		setTileType(TerrainType.empty);
	}

	public void setTileType(TerrainType tileType) {
		this.tileType = tileType;
	}

	public TerrainType getTileType() {
		return tileType;
	}
	
	public Color getTileColor() {
		return getTileType().getDefaultColour();
	}
	
	public Image getTileImage() {
		BufferedImage img = null;		
		
		try {
			img = ImageIO.read(new File(getTileType().getDefaultImageFile()));
		} catch (IOException e) {
			e.printStackTrace();
		}
			
		return img;
	}

	public void draw(Graphics g, int x, int y) {
		g.translate(x, y);
		g.drawImage(getTileImage(), 0, 0, 32, 32, 0, 0, 32, 32, null);
		g.setColor(Color.DARK_GRAY);
		g.drawLine(0, 32, 32, 32);
		g.drawLine(32, 32, 32, 0);
		g.translate(-x, -y);
	}
}
